package com.zhengdongzulin.zuke.app.work.vm

import androidx.lifecycle.rxLifeScope
import com.lxj.androidktx.livedata.StateLiveData
import com.zhengdongzulin.zuke.app.Api
import com.zhengdongzulin.zuke.app.data.*
import com.zhengdongzulin.zuke.base.BaseViewModel
import com.zhengdongzulin.zuke.parser.ObjectList
import com.zhengdongzulin.zuke.parser.Response
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class  ZKWorkListDetailVm : BaseViewModel() {

    var getWorkDetail: StateLiveData<WorkListDetailBean> = StateLiveData()

    /**
     * queryPath String	是	工单类别：待办任务，我的已办，我的发起，我的全部
     */
    fun getWorkDetailById(id: String) {
        rxLifeScope.launch(
            {
                var r = RxHttp.postJson(Api.GET_GON_GDAN_INFO_BY_ID)
                    .add("gongdanId", id)
                    .toResponse<WorkListDetailBean>()
                    .await()
                getWorkDetail.postValueAndSuccess(r)
            }, {
                assignment(it, getWorkDetail)
            }
        )
    }

    var end_gong_dan: StateLiveData<WorkListDetailBean> = StateLiveData()

    /**
     *  结束工单
     */
    fun end_gong_dan(id: String, processId: String, checkInfo: String, checkLevel: String) {
        rxLifeScope.launch(
            {
                var r = RxHttp.postJson(Api.END_GONG_DAN)
                    .add("id", id)
                    .add("processId", processId)
                    .add("checkInfo", checkInfo)
                    .add("checkLevel", checkLevel)
                    .toResponse<WorkListDetailBean>()
                    .await()
                end_gong_dan.postValueAndSuccess(r)
            }, {
                assignment(it, end_gong_dan)
            }
        )
    }


}